﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;

namespace SHomeWorkshop.LunarSF.StudentInfosManager.ValidationRules
{
    /// <summary>
    /// 描述验证类。
    /// </summary>
    public class DiscriptionRule : LValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string text = Format(value.ToString());
            if (string.IsNullOrWhiteSpace(text))
                return new ValidationResult(true, null); //“描述”可以为空。验证OK

            if (text.Length <= 40)
                return new ValidationResult(true, null); //验证OK
            else
                return new ValidationResult(false, "“描述”不能超过40个字符。"); //验证失败
        }

        public static string Format(string origin)
        {
            if (string.IsNullOrWhiteSpace(origin)) return "";
            return origin.Replace(" ", "").Replace("　", "").Replace("\t", "");
        }

    }
}
